package com.ssy.lingxi.enhance.handler.async;

import com.ssy.lingxi.message.api.feign.SystemMessageControllerFeign;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 异步服务 - 消息
 * @author fhj
 * @date 2020/11/20
 * @version 2.0.0
 */
@Slf4j
@Component
public class MessageAsyncService {

    @Resource
    private SystemMessageControllerFeign systemMessageControllerFeign;

    /**
     * 发送系统消息
     * @param memberId 会员ID
     * @param roleId 角色ID
     * @param messageTemplateCode 消息提醒枚举
     * @param params 扩展参数
     */
    @Async
    public void sendSystemMessage(Long memberId, Long roleId, String messageTemplateCode, List<String> params) {
        try {
            SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
            systemMessageRequest.setMemberId(memberId);
            systemMessageRequest.setRoleId(roleId);
            systemMessageRequest.setMessageNotice(messageTemplateCode);
            systemMessageRequest.setParams(params);
            systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
        } catch (Exception e) {
            log.info("调用报表服务发送系统消息接口失败：{}", e.getMessage());
        }
    }

    /**
     * 批量发送系统消息
     * @param systemMessageRequestList SystemMessageRequest集合
     */
    @Async
    public void batchSendSystemMessage(List<SystemMessageRequest> systemMessageRequestList) {
        try {
            systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
        } catch (Exception e) {
            log.info("调用报表服务发送系统消息接口失败：{}", e.getMessage());
        }
    }
}
